package demo2;
public class Test {
    public static void main(String[] args) {
        Outer04 outer04 = new Outer04();
        outer04.method();
    }
}
class Outer04{
    private int n1=10;
    public void method(){
        //底层创建匿名内部类之后，立马就创建了一个对象，地址返回给了tiger这个对象
        //tiger对象的编译类型IA接口
        //tiger对象的运行类型Outer04$1
        IA tiger = new IA(){
            @Override
            public void cry() {
                    System.out.println("老虎在叫唤.....");
                }
        };
        tiger.cry();
        System.out.println(tiger.getClass());

        //演示基于类的匿名内部类
        //father对象的编译类型Father
        //father对象的运行类型Outer04$2
        Father father = new Father("jack"){
            @Override
            public void test() {
                System.out.println("匿名内部类重写我们的test方法");
            }
        };
        System.out.println(father.getClass());
        father.test();

        //基于抽象类
        Animal animal = new Animal() {
            @Override
            void eat() {
                System.out.println("小狗吃骨头");
            }
        };
        animal.eat();
    }
}
interface IA{
    public void cry();
}

//class Tiger implements IA{
//    @Override
//    public void cry() {
//        System.out.println("老虎在叫唤.....");
//    }
//}

class Father{
    public Father(String name){
        System.out.println("接收到的名字就是"+name);
    }
    public void test(){}
}

abstract class Animal{
    abstract void eat();
}
